//
//  LoginViewController.m
//  Project1.0
//
//  Created by dllo on 15/10/15.
//  Copyright (c) 2015年 吴帅. All rights reserved.
//

#import "WSLoginViewController.h"
#import "WSLoginView.h"
#import <BmobSDK/Bmob.h>
#import "WSRegistViewController.h"

@interface WSLoginViewController ()<LoginViewDelegate>

@end

@implementation WSLoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    WSLoginView *loginView = [[WSLoginView alloc] initWithFrame:self.view.frame];
    loginView.delegate = self;
    [self.view addSubview:loginView];
}

- (void)changeImage:(UIButton *)button{

}

- (void)returnAction{

    [self.navigationController dismissViewControllerAnimated:YES completion:nil];
}

- (void)loginWithUserName:(NSString *)userName passWord:(NSString *)passWord {

    [BmobUser loginWithUsernameInBackground:userName password:passWord block:^(BmobUser *user, NSError *error) {
        
        if (user != nil) {
            [[NSUserDefaults standardUserDefaults] setObject:user.objectId forKey:@"uId"];
            [[NSUserDefaults standardUserDefaults] setObject:@"1" forKey:@"isLogin"];
            [self.delegate changeUserName];
            [self.navigationController dismissViewControllerAnimated:YES completion:nil];
            
        }
        else {
        
            NSLog(@"用户名或密码错误");
        }
    }];
}

- (void)pushRegistViewController {

    WSRegistViewController *registVC = [[WSRegistViewController alloc] init];
    [self.navigationController pushViewController:registVC animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
